<?php


namespace app\api\logic;


use app\common\enum\DefaultEnum;
use app\common\logic\BaseLogic;
use app\common\model\goods\Goods;
use app\common\model\staff\Staff;

class StaffLogic extends BaseLogic
{
    /**
     * @notes 师傅详情
     * @param $id
     * @return array
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     * @author ljj
     * @date 2022/2/23 6:34 下午
     */
    public function detail($id)
    {
        $result = Staff::where(['id'=>$id])
            ->field('id,user_id,name,mobile,goods_ids,province_id,city_id,district_id,address,create_time')
            ->append(['user_image','province','city','district'])
            ->findOrEmpty()
            ->toArray();

        if ($result) {
            $goods_ids = explode(',',trim($result['goods_ids'],','));
            $result['goods'] = Goods::where(['id'=>$goods_ids,'status'=>DefaultEnum::SHOW])
                ->field('id,name,unit_id,image,price')
                ->append(['unit_desc'])
                ->select()->toArray();
        }

        return $result;
    }
}